package com.wondream.myframework.app.common.aspect;

import com.wondream.myframework.app.common.annotation.AuthControlAnno;
import com.wondream.myframework.app.common.annotation.DecryptAnno;
import com.wondream.myframework.app.common.exception.BusinessExeceptionCode;
import com.wondream.myframework.app.common.util.FieldUtils;
import com.wondream.myframework.app.common.util.SpringUtils;
import com.wondream.myframework.app.vo.base.OpRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 订单号解密处理
 */
@Aspect
@Component
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
public class AuthControlAspect {

    /**
     * 切入点
     */
    @Pointcut("@annotation(com.wondream.myframework.app.common.annotation.AuthControlAnno)")
    public void pointCut() {

    }

    /**
     * 拦截要执行的目标方法
     */
    @Around("pointCut()")
    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
        String op = "AuthControlAspect.aroundAdvice";
        MethodSignature ms = (MethodSignature) pjp.getSignature();
        Method method = ms.getMethod();
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes) requestAttributes;
        HttpServletRequest request = sra.getRequest();
        Object[] arguments = pjp.getArgs();
        AuthControlAnno authControl = AnnotationUtils.findAnnotation(method, AuthControlAnno.class);
        if (authControl != null) {

        }
        return pjp.proceed();
    }
}
